package com.xuexiang.xuidemo.slice.imageview.edit;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.ability.PhotoEditorAbility;

public class ImageEditSlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_image_edit_layout);
        initView();
    }

    private void initView() {
        setClick(ResourceTable.Id_et_img_crop);
        setClick(ResourceTable.Id_et_img_enhancement_process);
        setClick(ResourceTable.Id_et_img_imageView);
        setClick(ResourceTable.Id_image_back);
    }

    private void setClick(int id) {
        findComponentById(id).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                terminate();
                break;
            case ResourceTable.Id_et_img_crop:
                present(new ImageCropSlice(), new Intent());
                break;
            case ResourceTable.Id_et_img_enhancement_process:
                present(new ImageEnhanceSlice(), new Intent());
                break;
            case ResourceTable.Id_et_img_imageView:
                //   present(new PhotoEditSlice(), new Intent());
                Intent intent = new Intent(); //
                intent.setOperation(new Intent.OperationBuilder()
                    .withBundleName(getContext().getBundleName())
                    .withAbilityName(PhotoEditorAbility.class)
                    .build());
                startAbility(intent);
                break;
        }
    }
}
